// pending-未完成 fulfilled-完成 rejected-失败
function run (fun) {
  const oldFetch = window.fetch;
  const cache = {
    status: "pending",
    data: null
  };
  const newFetch = (...args) => {
    if (cache.status === "fulfilled") {
      return cache
    } else if (cache.status === "rejected") {
      throw new cache.value;
    }
    const p = oldFetch(...args).then(res=> res.json()).then(res => {
      cache.status = "fulfilled";
      cache.data = res
    }).catch(err => {
      cache.status = "rejected";
      cache.data = err
    })
    throw p
  }
  window.fetch = newFetch
  try {
    fun()
  } catch(err) {
    if (err instanceof Promise) {
      err.finally(() => {
        window.fetch = newFetch
        fun()
        window.fetch = oldFetch
      })
      fun()
    }
  }
  
  window.fetch = oldFetch
}